import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;


public class FindYourPassMain {
	JTextField t1;
	JTextField t2;
	int[] pass=new int[6];
	JFrame jf;
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new FindYourPassMain().go();
	}
	
	private void go() {
		jf=new JFrame();
		jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		jf.setLayout(new BoxLayout(jf.getContentPane(), BoxLayout.Y_AXIS));
		JLabel l1=new JLabel("your name:");
		t1=new JTextField(10);
		JButton b1=new JButton("getPass");
		JLabel l2=new JLabel("your pass is:");
		t2=new JTextField(10);
		
		b1.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				String name=t1.getText();
				String [] p1=name.split(" ");
				int idx=0;
				String p="";
				for(String s:p1) {
					pass[idx]=changeStringToNumber(s);
					if((pass[idx])<10) {
						p=p+"0"+String.valueOf(pass[idx]);
					}else {
						p=p+String.valueOf(pass[idx]);
					}
					idx++;
				}
				
				t2.setText(p);
				System.out.println(p);
				
			}

			private int changeStringToNumber(String s) {
				int result=0;
				for(char c:s.toCharArray()) {
					int number=c-'a'+1;
					result+=number;
					System.out.println("### "+c+"="+number);
				}
				System.out.println("######### next #########");
				return result;
			}
		});
		
		
		jf.add(l1);
		jf.add(t1);
		jf.add(b1);
		jf.add(l2);
		jf.add(t2);
		
		jf.pack();
		jf.setVisible(true);
	}

}
